package cabbage.model.logic;
import java.sql.SQLException;

import cabbage.database.idao.ILiveCollectibleDAO;
import cabbage.database.idao.IPlayerDAO;
import cabbage.database.operations.LiveCollectibleDAO;
import cabbage.database.operations.PlayerDAO;
import cabbage.logic.i.ICollectedGamePlay;

public class CollectedGamePlay implements ICollectedGamePlay {
	
	private IPlayerDAO player;
	private ILiveCollectibleDAO liveCollectible;
	
	public CollectedGamePlay() {
		
	}
	
	@Override
	public int createCollected(int playerid, int livecollectibleid) throws SQLException {
		if (!checkPlayerExists(playerid)) return 0;
		if (!checkLiveCollectibleExists(livecollectibleid)) return 0;
		if ( checkForDuplicate(playerid,livecollectibleid)) return 0;
		return player.addInventory(playerid, livecollectibleid);
	}
	
	private boolean checkPlayerExists(int playerid) throws SQLException {
		player = new PlayerDAO();
		return player.checkPlayeridExists(playerid);
	}
	
	private boolean checkLiveCollectibleExists(int livecollectibleid) throws SQLException {
		liveCollectible = new LiveCollectibleDAO();
		return liveCollectible.checkLiveCollectibleidExists(livecollectibleid);
	}
	
	private boolean checkForDuplicate(int playerid, int livecollectibleid) throws SQLException {
		player = new PlayerDAO();
		return player.checkPlayerHasInventory(playerid, livecollectibleid);
	}

}


